export default class ParticleSystem {
  constructor(game) {
    this.game = game;
    this.particles = [];
  }
  
  createParticles(x, y, color, count = 10, speed = 3, size = 5, lifetime = 30) {
    for (let i = 0; i < count; i++) {
      this.particles.push({
        x,
        y,
        color,
        size: Math.random() * size + 2,
        speedX: (Math.random() - 0.5) * speed,
        speedY: (Math.random() - 0.5) * speed,
        lifetime,
        maxLifetime: lifetime,
        alpha: 1
      });
    }
  }
  
  update() {
    for (let i = this.particles.length - 1; i >= 0; i--) {
      const particle = this.particles[i];
      
      // 更新位置
      particle.x += particle.speedX;
      particle.y += particle.speedY;
      
      // 更新生命周期
      particle.lifetime--;
      particle.alpha = particle.lifetime / particle.maxLifetime;
      
      // 移除过期粒子
      if (particle.lifetime <= 0) {
        this.particles.splice(i, 1);
      }
    }
  }
  
  render(ctx) {
    for (const particle of this.particles) {
      ctx.globalAlpha = particle.alpha;
      ctx.fillStyle = particle.color;
      ctx.beginPath();
      ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
      ctx.fill();
    }
    ctx.globalAlpha = 1;
  }
} 